/**
 * 
 */
package neptune.web.client.view.components;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Vathalas
 * 
 */
public class MessageWidget extends Composite {

	public static final int MESSAGE = 0;
	public static final int ERROR = 1;
	public static final int LOADING = 2;
	private Widget mainWidget;
	private SimplePanel mainPanel;

	public MessageWidget(int type, String message) {
		if (message == null) {
			switch (type) {
			case MESSAGE:
				message = "";
				break;
			case ERROR:
				message = "Error";
				break;
			case LOADING:
				message = "Loading";
				break;
			default:
				message = "";
			}
		}

		mainPanel = new SimplePanel();

		mainWidget = new Label(message);
		mainPanel.setWidget(mainWidget);

		initWidget(mainPanel);

		// Styles
		this.setStylePrimaryName("MessageWidget");
		mainWidget.setStylePrimaryName("MessageWidget-label");
		if (type == ERROR)
			this.addStyleDependentName("Error");
		if (type == LOADING)
			this.addStyleDependentName("Loading");
	}

	public MessageWidget(int type) {
		this(type, null);
	}

	/**
	 * @return the mainWidget
	 */
	public Widget getMainWidget() {
		return mainWidget;
	}

	/**
	 * @param mainWidget
	 *            the mainWidget to set
	 */
	public void setMainWidget(Widget mainWidget) {
		this.mainWidget = mainWidget;
		mainPanel.setWidget(mainWidget);
	}

}
